package summaryRanges;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<String> summaryRanges(int[] nums) {
        // 最小有序区间
        List<String> list = new ArrayList<>();
        int start = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if(nums[i] == nums[i-1] + 1) {
                continue;
            }else {
                StringBuilder sb = new StringBuilder();
                if(start == nums[i-1]) {
                    sb.append(start);
                }else {
                    sb.append(start).append("->").append(nums[i-1]);
                }
                list.add(sb.toString());
                start = nums[i];
            }
        }
        if(start == nums[nums.length-1]) {
            list.add(Integer.toString(start));
        }else {
            list.add(Integer.toString(start) + "->" + Integer.toString(nums[nums.length-1]));
        }
        return list;
    }
}
